
package com.epfresh.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.epfresh.R;
import com.epfresh.bean.MarketBean;
import com.epfresh.bean.TypeBean;

import multitype.ItemViewBinder;
import multitype.OnRecyclerViewItemClickListener;

public class ViewBinderAreaTopGrid
    extends ItemViewBinder<TypeBean, ViewBinderAreaTopGrid.ViewHolder> implements View.OnClickListener{
    OnRecyclerViewItemClickListener onRecyclerViewItemClickListener;

    public OnRecyclerViewItemClickListener getOnRecyclerViewItemClickListener() {
        return onRecyclerViewItemClickListener;
    }

    public void setOnRecyclerViewItemClickListener(OnRecyclerViewItemClickListener onRecyclerViewItemClickListener) {
        this.onRecyclerViewItemClickListener = onRecyclerViewItemClickListener;
    }
    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        //View view = inflater.inflate(R.layout.include_market_head, parent, false);item_depart_text
        View view = inflater.inflate(R.layout.item_depart_text, parent, false);
        return new ViewHolder(view);
    }


    @Override
    protected void onBindViewHolder(@NonNull ViewHolder vhStores, @NonNull TypeBean flag) {
        vhStores.tv_depart.setTag(R.id.item_key_position, getPosition(vhStores));
        MarketBean.MarketAreasBean marketAreasBean = flag.getMarketAreasBean();
        if(marketAreasBean == null)
            return;
        vhStores.tv_depart.setTag(R.id.item_key_status, marketAreasBean);
        vhStores.tv_depart.setOnClickListener(this);
        vhStores.tv_depart.setText(marketAreasBean.getName());

    }

    @Override
    public void onClick(View v) {
        Log.e("bind click position","start");
        Object o = v.getTag(R.id.item_key_position);
        if (onRecyclerViewItemClickListener != null && o instanceof Integer) {
            Log.e("bind click position",""+o);
            onRecyclerViewItemClickListener.onItemClick(v, (Integer)o, v.getTag(R.id.item_key_status));
        }
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv_depart;


        ViewHolder(@NonNull View convertView) {
            super(convertView);
            tv_depart = (TextView)convertView.findViewById(R.id.tv_depart);

        }
    }
}
